'''
Created on 15/06/2012

@author: Ivanus
'''

from django.http import Http404, HttpResponse
from django.template import Context
from django.template.loader import get_template
from django.shortcuts import render_to_response

import datetime

def hello(request):
    #try:
    browser = request.META.get('HTTP_USER_AGENT', 'unknown')
    #except KeyError:
    #browser = 'unknown'
    return HttpResponse("Tu explorador es %s" % browser)
    #return HttpResponse("Hello world %s" % request.Meta.HTTP_USER_AGENT)

def index(request):
    return HttpResponse("Este es el index %s" % request.path)

def time(request):
    fecha = datetime.datetime.now()
    nombre = "Ivanus"
#    html = "Hoy es %s" % now
#    t = get_template('fecha_hora.html')
#    html = t.render(Context({'current_date': now}))
#    return HttpResponse(html)
    return render_to_response('fechas/fecha_hora.html', locals())

def hours_ahead(request, offset):
    try:
        offset = int(offset)
    except ValueError:
        raise Http404()
    dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
    html = "En %s hora(s), sera %s." % (offset, dt)
    return HttpResponse(html)

def display_meta(request):
    values = request.META.items()
    values.sort()
    html = []
    for k, v in values:
        html.append('<tr><td>%s</td><td>%s</td></tr>' % (k, v))
    return HttpResponse('<table>%s</table>' % '\n'.join(html))